package com.caseprocessing.api;

import java.util.List;

/**
 * SiliconFlow API消息模型
 * 支持文本和多模态内容
 */
public class Message {
    
    private String role;
    private Object content; // 可以是String或List<ContentPart>
    
    public Message() {}
    
    public Message(String role, String content) {
        this.role = role;
        this.content = content;
    }
    
    public Message(String role, List<ContentPart> content) {
        this.role = role;
        this.content = content;
    }
    
    public String getRole() {
        return role;
    }
    
    public void setRole(String role) {
        this.role = role;
    }
    
    public Object getContent() {
        return content;
    }
    
    public void setContent(Object content) {
        this.content = content;
    }
    
    public void setContent(String content) {
        this.content = content;
    }
    
    public void setContent(List<ContentPart> content) {
        this.content = content;
    }
    
    /**
     * 获取文本内容（如果是字符串类型）
     */
    public String getTextContent() {
        if (content instanceof String) {
            return (String) content;
        }
        return null;
    }
    
    /**
     * 获取多模态内容（如果是ContentPart列表）
     */
    @SuppressWarnings("unchecked")
    public List<ContentPart> getMultiModalContent() {
        if (content instanceof List) {
            return (List<ContentPart>) content;
        }
        return null;
    }
    
    /**
     * 消息构建器
     */
    public static MessageBuilder builder() {
        return new MessageBuilder();
    }
    
    public static class MessageBuilder {
        private String role;
        private Object content;
        
        public MessageBuilder role(String role) {
            this.role = role;
            return this;
        }
        
        public MessageBuilder content(String content) {
            this.content = content;
            return this;
        }
        
        public MessageBuilder content(List<ContentPart> content) {
            this.content = content;
            return this;
        }
        
        public Message build() {
            Message message = new Message();
            message.setRole(role);
            message.setContent(content);
            return message;
        }
    }
    
    @Override
    public String toString() {
        return "Message{role='" + role + "', content=" + content + "}";
    }
}